package cn.cms.dao;

import cn.cms.model.SysLog;
import org.jfaster.mango.annotation.DB;
import org.jfaster.mango.annotation.Rename;
import org.jfaster.mango.annotation.SQL;

import java.util.List;

@DB(
        table = "sys_log"
)
public interface SysLogDao {


    @SQL("insert into #table(type,name,login_name,real_name,src_ip,params,date_add) values(:type,:name,:loginName,:realName,:srcIp,:params,:dateAdd)")
    public void save(SysLog systemLog);

    @SQL("select * from #table " +
            " where 1=1 " +
            " #if (:temple==1) and login_name like CONCAT('%',:keyWords,'%') or real_name like CONCAT('%',:keyWords,'%') " +
            " #elseif (:temple==2) and params like CONCAT('%',:keyWords,'%') " +
            " #elseif (:temple==3) and name like CONCAT('%',:keyWords,'%') " +
            " #else " +
            " and (login_name like CONCAT('%',:keyWords,'%') " +
            " or real_name like CONCAT('%',:keyWords,'%') " +
            " or params like CONCAT('%',:keyWords,'%') " +
            " or name like CONCAT('%',:keyWords,'%')) " +
            " #end " +
            " #if (:type!='' && :type!=null) and type = :type #end " +
            " #if (:startTime!='' && :startTime!=null) and date_add > :startTime #end " +
            " #if (:endTime!='' && :endTime!=null) and date_add < :endTime #end " +
            " order by date_add desc "
    )
    public List<SysLog> getList(PageDao pageDao,
                                // 1-按登录名，2-按参数，3-按操作备注，null-三者兼具
                                @Rename("temple") String temple,
                                @Rename("keyWords") String keyWords,
                                @Rename("type") String type,
                                @Rename("startTime") String startTime,
                                @Rename("endTime") String endTime);

}
